# -*- coding: utf-8 -*- 
'''
Created on 2011-12-23

@author: TOM
'''

from django.db import models
from website.constant import STUDY_TYPES_CHOICES, WORKORDER_STATE_CHOICES, \
    ATTEND_CHOICES, COURSE_TYPE_CHOICES
from website.customercontrol.models import Student, TrainingContractDetail
from website.employecontrol.models import Employe
import datetime

# Create your models here.

#静态值表
class StaticValue(models.Model):
    sv_type=models.IntegerField(max_length=1,blank=True, null=True)#静态值类型 1 学习方式，2？
    code=models.CharField(max_length=200,blank=True, null=True)#编码 
    value=models.CharField(max_length=200,blank=True, null=True)#值 
    state=models.IntegerField(max_length=1,blank=True, null=True)#状态(1有效0无效)
    desc=models.CharField(max_length=200,blank=True, null=True)#静态值用途说明
    
    

#公司-分公司(校区)
class Company(models.Model):
    cn_name=models.CharField(max_length=200) #中文名称
    en_name=models.CharField(max_length=200) #英文名称
    registered_addr=models.CharField(max_length=50) #注册地址
    registered_date=models.DateField() #注册时间
    registered_fund=models.DecimalField(max_digits=10, decimal_places=2) #注册资金
    corporation=models.CharField(max_length=50,blank=True, null=True) #法人
    telephone=models.CharField(max_length=100,blank=True, null=True) #联系电话
    parent = models.ForeignKey('self',blank=True, null=True, related_name='child_company')
    

#部门
class Department(models.Model):
    name=models.CharField(max_length=80)
    leader=models.CharField(max_length=100,blank=True, null=True)
    parent = models.ForeignKey('self',blank=True, null=True, related_name='child_department')
    company=models.ForeignKey(Company,blank=True, null=True,related_name='department_school')

#职务
class Office(models.Model):
    name=models.CharField(max_length=50)
    parent = models.ForeignKey('self',blank=True, null=True, related_name='child_office')
    
#年级
class Grade(models.Model):
    name=models.CharField(max_length=50)
    
    def __unicode__(self):
        return self.name


#课程
class Course(models.Model):
    name=models.CharField(max_length=50)
    course_type=models.IntegerField(max_length=1,blank=True, null=True,choices=COURSE_TYPE_CHOICES)# 学习方式
    #grade=models.ManyToManyField(Grade,blank=True, null=True)
    
    def __unicode__(self):
        return self.name


#薪资等级 
class SalaryLevel(models.Model):
    base_salary=models.DecimalField(max_digits=10, decimal_places=2)   #基本工资
    performance_salary=models.DecimalField(max_digits=10, decimal_places=2)    #绩效工资
    secrecy_salary=models.DecimalField(max_digits=10, decimal_places=2) #保密工资
    traffic_subsidy=models.DecimalField(max_digits=10, decimal_places=2) #交通补贴
    comm_subsidy=models.DecimalField(max_digits=10, decimal_places=2) #通讯补贴
    salary_grade=models.CharField(max_length=10) #薪档
    position_level=models.CharField(max_length=10) #职位等级
    remark=models.CharField(max_length=50) #备注
    
    
    
#电子公告
class Notice(models.Model):
    employe=models.ForeignKey('employecontrol.Employe',blank=True, null=True,related_name='notice_employe')  #员工
    title=models.CharField(max_length=255) #标题
    valid_start=models.DateField() #有效开始时间
    valid_end=models.DateField()#有效结束时间
    is_top=models.CharField(max_length=2)#是否置顶
    content=models.TextField()#内容

#函件查看记录
class NoticeLookupLog(models.Model):
    notice=models.ForeignKey(Notice,blank=True, null=True,related_name='lookupLog_notice')
    noticer=models.ForeignKey('employecontrol.Employe',blank=True, null=True,related_name='lookupLog_noticer') 


#电子函件
class Letters(models.Model):
    sender=models.ForeignKey('employecontrol.Employe',blank=True, null=True,related_name='letters_employe') 
    receiver=models.ManyToManyField('employecontrol.Employe',blank=True, null=True)
    title=models.CharField(max_length=200,blank=True, null=True)
    content=models.CharField(max_length=1000,blank=True, null=True)
    send_time=models.DateTimeField(default=datetime.datetime.now())

#函件附件   
class LettersAttachment(models.Model):
    name=models.CharField(max_length=200,blank=True, null=True)
    path=models.CharField(max_length=200,blank=True, null=True)
    letters=models.ForeignKey(Letters,blank=True, null=True,related_name='letters_attachment')


#函件查看记录
class LettersLookupLog(models.Model):
    letters=models.ForeignKey(Letters,blank=True, null=True,related_name='lookupLog_letters')
    looker=models.ForeignKey('employecontrol.Employe',blank=True, null=True,related_name='lookupLog_looker') 

#排课信息     
class CourseRecord(models.Model):
    begin_time=models.DateTimeField()#上课开始时间 
    end_time=models.DateTimeField()# 上课结束时间
    study_type=models.IntegerField(max_length=1,blank=True, null=True,choices=STUDY_TYPES_CHOICES)# 学习方式
    grade=models.ForeignKey(Grade,blank=True, null=True,related_name='record_grade')# 年级
    course=models.ForeignKey(Course,blank=True, null=True,related_name='record_course')# 课程
    student=models.ForeignKey(Student,blank=True, null=True,related_name='record_student')# 学生ID
    teacher=models.ForeignKey(Employe,blank=True, null=True,related_name='record_teacher')# 教师
    student_manager=models.ForeignKey(Employe,blank=True, null=True,related_name='record_manager')#学管师
    

#课时真实记录
class CourseRealRecord(models.Model):
    create_time=models.DateField()#记录创建时间
    course=models.ForeignKey(Course,blank=True, null=True,related_name='real_record_course')# 课程
    study_type=models.IntegerField(max_length=1,choices=STUDY_TYPES_CHOICES)# 学习方式
    student=models.ForeignKey(Student,blank=True, null=True,related_name='real_record_student')# 学生
    grade=models.ForeignKey(Grade,blank=True, null=True,related_name='real_record_grade')# 年级
#    begin_time=models.DateTimeField()#上课开始时间
#    end_time=models.DateTimeField()# 上课结束时间
    begin_time=models.CharField(max_length=50,blank=True, null=True)#上课开始时间
    end_time=models.CharField(max_length=50,blank=True, null=True)# 上课结束时间
    course_hour=models.DecimalField(max_digits=10, decimal_places=2,blank=True, null=True)#课时
    attend=models.IntegerField(max_length=1,choices=ATTEND_CHOICES)# 出席情况(1, '迟到'),(2, '请假'),(3, '旷课'), 
    state=models.IntegerField(max_length=1,blank=True, null=True,choices=WORKORDER_STATE_CHOICES)#审核状态
    remark=models.CharField(max_length=200,blank=True, null=True)#备注
    company=models.ForeignKey(Company,blank=True, null=True,related_name='real_record_school')#校区
    teacher=models.ForeignKey(Employe,blank=True, null=True,related_name='real_record_teacher')# 教师
    student_manager=models.ForeignKey(Employe,blank=True, null=True,related_name='real_record_manager')#学管师        -- 当前员工ID
    szjy=models.ForeignKey(Employe,blank=True, null=True,related_name='real_record_szjy')#素质拓展师
    auditor=models.ForeignKey(Employe,blank=True, null=True,related_name='real_record_auditor')#审核人
    
#实时课时表
class CourseCurrentRecord(models.Model):
    student=models.ForeignKey(Student,related_name='course_current_student')# 学生ID
    grade=models.ForeignKey('resourcecontrol.Grade',related_name='course_current_grade')# 年级ID
    course=models.ForeignKey('resourcecontrol.Course',related_name='course_current_course')# 课程ID
    study_type=models.IntegerField(max_length=1,choices=STUDY_TYPES_CHOICES)# 学习方式
    course_times=models.DecimalField(max_digits=10, decimal_places=2,blank=True, null=True)#单个课程-总课时
    use_course_times=models.DecimalField(max_digits=10, decimal_places=2,blank=True, null=True)#已消耗课时
    #auditor=models.ForeignKey(Employe,blank=True, null=True,related_name='course_current_auditor')#审核人
    
class ScheduleRecord(models.Model):
    title=models.CharField(max_length=50,blank=True, null=True)
    start=models.DateTimeField(blank=True, null=True)
    end=models.DateTimeField(blank=True, null=True)
    loc=models.CharField(max_length=50,blank=True, null=True)
    url=models.URLField(blank=True, null=True)
    notes=models.CharField(max_length=500,blank=True, null=True)
    rem=models.CharField(max_length=10,blank=True, null=True)
    ad=models.BooleanField(default=False)   
    recorder=models.ForeignKey('employecontrol.Employe',blank=True, null=True,related_name='schedule_recorder') 
